import java.util.Scanner;


public class Homework {
    //符串中的单词数
    /*public static int countSegments(String s) {
       int segmentcount = 0;
        for (int i = 0; i < s.length(); i++) {
            if ((i == 0 || s.charAt(i-1) == ' ' )&& s.charAt(i) != ' ')
                segmentcount++;
        }
        return segmentcount;
    }

    public static void main(String[] args) {
        int ret = countSegments("Hello, my name is John");
        System.out.println(ret);

    }
*/
      public static int countSegments(String s){
          s = s.trim();
          if (s == null || s.isEmpty()){
              return 0;
          }
          int segmentcount = 0;
          String[] str = s.split(" " );
          for (int i = 0; i < str.length; i++) {
              if (str[i].isEmpty()) {
                  continue;
              }
              segmentcount++;
          }
          return  segmentcount;
      }

    public static void main1(String[] args) {
        int ret = countSegments("Hello, my name is John");
        System.out.println(ret);
    }
    //转换成小写字母
   /* public static   String toLowerCase(String s) {

        String s1 = s.toLowerCase();
        return  s1;
    }

    public static void main(String[] args) {
        String ret = toLowerCase("HELLO");
        System.out.println(ret);
    }*/

    public static String toLowerCase(String s) {
        if(s == null || s.length() == 0) {
            return null;
        }
        StringBuilder sb = new StringBuilder();
        for(int i = 0;i < s.length();i++) {
            char ch = s.charAt(i);
            //大写字母进行转换
            if(ch >= 'A' && ch <= 'Z') {
                sb.append((char)(ch+32));
            }else{
                //小写字母直接拼接
                sb.append(ch);
            }
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        String s = toLowerCase("HELLO");
        System.out.println(s);
    }
}
